package spring_annotation.config;

import org.springframework.context.annotation.*;
import spring_annotation.condition.LinuxCondition;
import spring_annotation.condition.MyImportBeanDefinitionRegistrar;
import spring_annotation.condition.MyImportSelector;
import spring_annotation.condition.WindowsCondition;
import spring_annotation.pojo.Color;
import spring_annotation.pojo.ColorFactoryBean;
import spring_annotation.pojo.Person;
import spring_annotation.pojo.Shape;

@Configuration
@Conditional(WindowsCondition.class)
@Import({
        Color.class,
        Shape.class,
        MyImportSelector.class,
        MyImportBeanDefinitionRegistrar.class
})
public class PersonConfig {

    @Lazy
    @Scope("singleton")
//    @Scope("prototype")
    @Bean(value = "person02")
    public Person person01() {
        System.out.println("Person 实例化");
        return new Person("lisi", 20, "ct");
    }

    @Conditional(WindowsCondition.class)
    @Bean("bill")
    public Person person02(){
        return new Person("Bill Gates", 62, "geek");
    }

    @Conditional(LinuxCondition.class)
    @Bean("linus")
    public Person person03(){
        return new Person("Linus", 55, "science");
    }

    @Bean
    public ColorFactoryBean colorFactoryBean(){
        return new ColorFactoryBean();
    }

}
